package org.example.new_hbps_backend_reconstruction.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.example.new_hbps_backend_reconstruction.entity.BloodOxygenLogsEntity;
import org.example.new_hbps_backend_reconstruction.mapper.BloodOxygenLogsMapper;
import org.example.new_hbps_backend_reconstruction.service.BloodOxygenLogsService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * @author 丁利军
 * @date 2025年10月15日 21:51
 * @description TODO: 描述
 */

@Service
@RequiredArgsConstructor
public class BloodOxygenLogsServiceImpl implements BloodOxygenLogsService {

    private final BloodOxygenLogsMapper bloodOxygenLogsMapper;

    @Override
    public BloodOxygenLogsEntity getLatestByPatientUid(Long patientUid) {
        return bloodOxygenLogsMapper.findLatestByPatientUid(patientUid);
    }

    @Override
    public IPage<BloodOxygenLogsEntity> getPageByPatientUid(Long patientUid, int pageNum, int pageSize) {
        Page<BloodOxygenLogsEntity> page = new Page<>(pageNum, pageSize);
        return bloodOxygenLogsMapper.selectPageByPatientUid(page, patientUid);
    }

    @Override
    public List<BloodOxygenLogsEntity> getByPatientUidAndDate(Long patientUid, LocalDate date) {
        return bloodOxygenLogsMapper.findByPatientUidAndDate(patientUid, date);
    }

    @Override
    public List<BloodOxygenLogsEntity> getAllByPatientUid(Long patientUid) {
        return bloodOxygenLogsMapper.findAllByPatientUid(patientUid);
    }

    @Override
    public Long countByPatientUidAndDate(Long patientUid, LocalDate date) {
        return bloodOxygenLogsMapper.countByPatientUidAndDate(patientUid, date);
    }

    @Override
    public Double averageSpo2ByPatientUidAndDate(Long patientUid, LocalDate date) {
        return bloodOxygenLogsMapper.averageSpo2ByPatientUidAndDate(patientUid, date);
    }
}
